home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / includes / mobileExplorerFunctions.php < prev    next >
PHP Script  |  2010-05-19  |  24KB  |  600 lines

  1. <?php
  2. /**
  3.  * Common explorer functions used by scripts displaying mobile devices pages
  4.  *
  5.  *
  6.  * PHP version 5
  7.  *
  8.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category   NA
  15.  * @package    NA
  16.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  17.  * @copyright  2005-2008 Nicolas Bruley / Peer 2 World
  18.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19.  * @version    CVS: $Id:$
  20.  * @link       http://www.weezo.net
  21.  * @since      File available since Release 1.3.0
  22.  */
  23.  
  24. require_once(INCLUDE_DIR.'mobileFunctions.php');
  25. require_once(INCLUDE_DIR.'outputFunctions.php');
  26.  
  27. /**
  28.  * @desc Initialize mobile explorer specific settings
  29.  *
  30.  */
  31. function mefExplorerInit(){
  32.     if(cfRGetVar('resourceMobileConfigured')) return ;
  33.  
  34.     cfRInitVar('itemsPerPageMobile',30); // Items per page - 0: unlimited, 10, 20, 50
  35.     cfRSetVar('itemsPerPage',cfRGetVar('itemsPerPageMobile')); // Items per page. Use itemsPerPageMobile for initiatlisation
  36.     cfRSetVar('itemsPerPagePos',0); // Current position (offset) in files
  37.  
  38.     // Default shrinked / expanded image view (0: shrinked, 1: expanded, 2:fullsize)
  39.     cfRInitVar('viewImageZoom',0);
  40.  
  41.     // Update directory content to see if some files are in it, in order to automatically select file/folder view
  42.     efDirUpdate(array('noThumbnails'=>1));
  43.  
  44.     // If no files in, display folder view, else display files view
  45.     if($_ENV['weezoResEfFiles']['nbFiles']==0) cfRSetVar('view','folders'); else cfRSetVar('view','files');
  46.  
  47.     // Adjust audio player to browser capabilities
  48.     if(!cfBGetVar(cfRGetVar('audioPlayer'))) cfRSetVar('audioPlayer',((cfBGetVar('flash'))?'flash':((cfBGetVar('wmp'))?'wmp':((cfBGetVar('qt'))?'qt':'qtReenc'))));
  49.  
  50.     cfRSetVar('resourceMobileConfigured',1);
  51. }
  52.  
  53. /**
  54.  * Entry point for mobile explorer scripts
  55.  *
  56.  */
  57. function mefExplorer(){
  58.  
  59.     // Init explorer mobile-specific data
  60.     mefExplorerInit();
  61.  
  62.     /*
  63.      ***************************************************************************************************************************
  64.      * Process POST commands
  65.      ***************************************************************************************************************************
  66.      */
  67.     efProcessPOST();
  68.     if(isset($_POST['uploadGetId'])) require(INCLUDE_DIR.'uploadWindow.php');
  69.  
  70.     /*
  71.      ***************************************************************************************************************************
  72.      * Get files and subfolders list, generate thumbnails if needed
  73.      ***************************************************************************************************************************
  74.      */
  75.     efDirUpdate(array('includeRights'=>1,'noExtra'=>1)+((cfRGetVar('fileTypeFilter')!=array('image'))?array('noThumbnails'=>1):array()));
  76.  
  77.     /*
  78.      ***************************************************************************************************************************
  79.      * Insert HEAD, JS functions and form
  80.      ***************************************************************************************************************************
  81.      */
  82.     mfInsertHead(array('topControlsExtra'=>mefTopControls()));
  83.     mefInsertScripts();
  84.  
  85.  
  86.     // Images thumbnails generation & monitoring
  87.     if(isset($_ENV['thumbnailPhotoNeeded']) && is_array($_ENV['thumbnailPhotoNeeded'])) efMakePhotoThumbnails($_ENV['thumbnailPhotoNeeded']); unset($_ENV['thumbnailPhotoNeeded']);
  88.  
  89.     if(!cfIsAsync() && cfRGetVar('view')!='tools') echo '<div id="mainDiv"></div>';
  90.  
  91.     // If user is browsing folders
  92.     if(cfRGetVar('view')=='folders')
  93.         mefDisplayFolders();
  94.  
  95.     // If user is browsing files
  96.     if(cfRGetVar('view')=='files')
  97.         mefDisplayFiles();
  98.  
  99.     // If user is viewing tools (mdl, upload, remote dl...)
  100.     if(cfRGetVar('view')=='tools')
  101.         mefDisplayTools();
  102. }
  103.  
  104. /**
  105.  * @desc Insert scripts needed by explorers
  106.  *
  107.  */
  108. function mefInsertScripts(){
  109.     if(cfIsAsync()) return ;
  110.     //outInsertStandardComForm($_SERVER['PHP_SELF'],cfUTF8Encode(cfResourceRelativePath(cfRGetVar('efCurrentDirectory'))));
  111.     outInsertStandardComForm($_SERVER['PHP_SELF'],cfUTF8Encode(cfResourceRelativePath(cfRGetVar('efCurrentDirectory'))));
  112.  
  113.     // Common explorer js functions
  114.     if(!cfBGetVar('inlineJS')) echo cfScriptLink('mExplorer.js');
  115.  
  116.     // Javascript
  117. ?>
  118. <script type="text/javascript">
  119. var eV="<?php echo cfRGetVar('view');?>";
  120. var icoSdown='<?php echo outIcon('sdown');?>';
  121. var icoSup='<?php echo outIcon('sup');?>';
  122. var icoFold='<?php echo outIcon('fi/med/folder'); ?>';
  123. var icoGo='/themes/mobile/go.gif';
  124. var capRen="<?php echo cfCaptionJS('explorerEnterNewName');?>";
  125. var capSup="<?php echo cfCaptionJS('genConfirmSuppress');?>";
  126. var capExe="<?php echo cfCaptionJS('explorerEnterParameters');?>";
  127. <?php
  128. // iPhone orientation management
  129. if(cfBGetVar('name')=='iPhone'){?>
  130. function updateOrientation(){
  131.     if(window.orientation==undefined) return;
  132.     if(Math.abs(orientation)==90) {
  133.         dgn('viewport').setAttribute("content", "width=480, height=268, user-scalable=yes,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0");
  134.         D.body.style.height='268px';
  135.     }
  136.     else {
  137.         dgn('viewport').setAttribute("content", "width=320, height=416, user-scalable=yes,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0");
  138.         D.body.style.height='416px';
  139.     }
  140. }
  141. <?php
  142. }
  143.  
  144. // Inline explorer scripts
  145. if(cfBGetVar('inlineJS')) echo file_get_contents(cfAppDocRoot().'/js/mExplorer.js');
  146.  
  147. /***************************************************************************************************************
  148.  * All files (explorer)
  149.  **************************************************************************************************************/
  150. if(cfRGetVar('fileTypeFilter')==false){
  151. ?>
  152. function updtFiles(fl,prev,next){
  153.     files=fl;
  154.     fS=-1;
  155.     eV='files';setViewIco();
  156.     var out='<table class="liTable" cellspacing=0 cellpadding=0><colgroup><col width="1%"><col width="98%"><col width="1%"></colgroup>';
  157.     if(prev) out+='<tr class="li" onclick="setPos(this,\'prev\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="<?php echo outIcon('sup');?>"></td><td class="lir"> </td></tr>';
  158.  
  159.     for(i=0;i<fl.length;i++) {
  160.         out+='<tr id="tr'+i+'" class="li" onclick="sel(this,0)"><td class="lil"><p class="frLi16"><img src="'+fl[i][2]+'"></p></td><td class="lic"><div class="lits">'+fl[i][1]+'</div>'+fl[i][5]+'</td><td class="lir"><img src="'+icoGo+'"></td></tr>';
  161.     }
  162.     if(next) out+='<tr class="li" onclick="setPos(this,\'next\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="<?php echo outIcon('sdown');?>"></td><td class="lir"> </td></tr>';
  163.     updtView(out+'</table>');
  164. }
  165. <?php
  166. }
  167.  
  168. /***************************************************************************************************************
  169.  * Audio files
  170.  **************************************************************************************************************/
  171. if(cfRGetVar('fileTypeFilter')==array('audio')){
  172. ?>
  173. function updtFiles(fl,prev,next){
  174.     files=fl;
  175.     fS=-1;
  176.     eV='files';setViewIco();
  177.     var out='<table class="liTable" cellspacing=0 cellpadding=0><colgroup><col width="1%"><col width="98%"><col width="1%"></colgroup>';
  178.  
  179. <?php
  180.     // If browser / OS supports playlists, add playlist-related control
  181.     if(cfBGetVar('playlistFormat')) {?>
  182. if(fl.length) out+='<tr class="li" onclick="mAddAll(this)" id="mAddTr"><td style="width:70px" class="lil"><img src="<?php echo outIcon('addMult')?>" class="ico"></td><td class="lic lit"><?php echo addslashes(cfCaption('explorerAudioPlaylistAdd'));?></td><td class="lir"> </td></tr><?php echo mfListSpacer();?>';
  183. <?php
  184.     } // eo playlist
  185.  
  186.     // Previous files control
  187. ?>
  188.     if(prev) out+='<tr class="li" onclick="setPos(this,\'prev\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="<?php echo outIcon('sup');?>"></td><td class="lir"> </td></tr>';
  189.  
  190.     <?php // Files ?>
  191.     for(i=0;i<fl.length;i++) {
  192.     out+='<tr id="tr'+i+'" class="li"><?php
  193.     if(cfBGetVar('name')=='IEMobile'){
  194.     ?>
  195. <td class="lil"><a href="javascript:view(dgi(\'tr'+i+'\'))"><img src="<?php echo outIcon('play')?>" class="nfrLi32"></a><?php } else { ?>
  196. <td class="lil"><img src="<?php echo outIcon('play')?>" class="nfrLi32" onclick="view(dgi(\'tr'+i+'\'))"><?php }
  197.     if(cfBGetVar('playlistFormat')) {
  198.         if(cfBGetVar('name')=='IEMobile')
  199.             echo '<a href="javascript:mAdd(dgi(\\\'tr\'+i+\'\\\'),\\\'pl\\\')"><img src="'.outIcon('add').'" class="nfrLi32"></a>';
  200.         else
  201.             echo '<img src="'.outIcon('add').'" class="nfrLi32" onclick="mAdd(dgi(\\\'tr\'+i+\'\\\'),\\\'pl\\\')">';
  202.     }
  203.         ?></td><td class="lic" onclick="sel(this.parentNode,0)"><div class="lits">'+fl[i][1]+'</div>'+fl[i][6]+'</td><td class="lir" onclick="sel(this.parentNode,0)"><img src="'+icoGo+'"></td></tr>';
  204.     }
  205.     if(next) out+='<tr class="li" onclick="setPos(this,\'next\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="<?php echo outIcon('sdown');?>"></td><td class="lir"> </td></tr>';
  206.  
  207.     updtView(out+'</table>');
  208. }
  209. <?php
  210. }
  211.  
  212. /***************************************************************************************************************
  213.  * Video or multimedia files
  214.  **************************************************************************************************************/
  215. if(is_array(cfRGetVar('fileTypeFilter')) && in_array('video',cfRGetVar('fileTypeFilter'))){
  216. ?>
  217. function updtFiles(fl,prev,next){
  218.     files=fl;
  219.     fS=-1;
  220.     eV='files';setViewIco();
  221.     var out='<table class="liTable" cellspacing=0 cellpadding=0><colgroup><col width="1%"><col width="98%"><col width="1%"></colgroup>';
  222.     if(prev) out+='<tr class="li" onclick="setPos(this,\'prev\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="<?php echo outIcon('sup');?>"></td><td class="lir"> </td></tr>';
  223.  
  224.     for(i=0;i<fl.length;i++) {
  225.         out+='<tr id="tr'+i+'" class="li"><td class="lil" onclick="view(this.parentNode)"><img src="<?php echo outIcon('play')?>" class="frLi2"></td><td class="lic" onclick="sel(this.parentNode,0)"><div class="lits">'+fl[i][1]+'</div></td><td class="lir" onclick="sel(this.parentNode,0)"><img src="'+icoGo+'"></td></tr>';
  226.     }
  227.     if(next) out+='<tr class="li" onclick="setPos(this,\'next\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="<?php echo outIcon('sdown');?>"></td><td class="lir"> </td></tr>';
  228.     updtView(out+'</table>');
  229. }
  230. <?php
  231. }
  232.  
  233.  
  234. /***************************************************************************************************************
  235.  * Images files
  236.  **************************************************************************************************************/
  237. if(cfRGetVar('fileTypeFilter')==array('image')){
  238. ?>
  239. var cT,margin=0;
  240. function sT(){cT=new Date().getTime()}
  241. function iS(i){
  242.     if(fS==i) return;
  243.     if(fS!=-1){
  244.         cn=dgi('td'+fS).childNodes;
  245.         cn[0].style.display='';
  246.         while(cn.length>1) dgi('td'+fS).removeChild(cn[1]);
  247.     }
  248.     fS=i;
  249.     return view();
  250. }
  251. function updtFiles(fl,prev,next){
  252.     files=fl;
  253.     fS=-1;
  254.     eV='files';setViewIco();
  255.     out='';
  256.     if(prev) out+='<table class="liTable" cellspacing=0 cellpadding=0><colgroup><col width="1%"><col width="89%"><col width="10%"></colgroup><tr class="li" onclick="setPos(this,\'prev\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="'+icoSup+'"></td><td class="lir"> </td></tr></table><br/>';
  257.  
  258.     for(i=0;i<fl.length;i++) {
  259.         out+='<img <?php if(cfRGetVar('fileViewAllowed')) {?>onclick="iS('+i+')"<?php } ?> src="'+fl[i][2]+'" style="width:'+imgw+'px;height:'+imgh+'px;margin:'+margin+'px">';
  260.     }
  261.  
  262.  
  263.     if(next) out+='<br/><table class="liTable" cellspacing=0 cellpadding=0><colgroup><col width="1%"><col width="89%"><col width="10%"></colgroup><tr class="li" onclick="setPos(this,\'next\')"><td class="lil"> </td><td class="lic" style="text-align:center"><img src="'+icoSdown+'"></td><td class="lir"> </td></tr></table>';
  264.     updtView('<div class="frame1">'+out+'</div>');
  265. }
  266. <?php
  267. }
  268. ?>
  269. var vA=new Array();
  270. vA['dlBt']=new Array("dl(this)","<?php echo outIcon('dl');?>","<?php echo cfCaption('genDownload');?>");
  271. <?php
  272.  
  273. // Multiple download / playlist add
  274. if(is_array(cfRGetVar('fileTypeFilter')) && (in_array('audio',cfRGetVar('fileTypeFilter'))||in_array('video',cfRGetVar('fileTypeFilter')))){
  275. ?>
  276. vA['mdlBt']=new Array("mAdd(this,'pl')","<?php echo outIcon('mdl');?>","<?php echo cfCaption('explorerAudioPlaylistAdd');?>");
  277. <?php
  278. }
  279. else{
  280. ?>
  281. vA['mdlBt']=new Array("mAdd(this)","<?php echo outIcon('mdl');?>","<?php echo cfCaption('explorerMultipleDownloadAdd');?>");
  282. <?php
  283. }
  284. // View
  285. if(is_array(cfRGetVar('fileTypeFilter')) && (in_array('audio',cfRGetVar('fileTypeFilter'))||in_array('video',cfRGetVar('fileTypeFilter')))){?>
  286. vA['plBt']=new Array("view(this)","<?php echo outIcon('play');?>","<?php echo cfCaption('explorerAudioPlay');?>");
  287. <?php } else{ ?>
  288. vA['plBt']=new Array("view(this)","<?php echo outIcon('view');?>","<?php echo cfCaption('genView');?>");
  289. <?php }?>
  290. vA['renBt']=new Array("ren(this)","<?php echo outIcon('edit');?>","<?php echo cfCaption('explorerRename');?>");
  291. vA['exeBt']=new Array("exe(this)","<?php echo outIcon('exec');?>","<?php echo cfCaption('explorerExecute');?>");
  292. vA['supBt']=new Array("sup(this)","<?php echo outIcon('cancel');?>","<?php echo cfCaption('genDelete');?>");
  293. </script>
  294. <?php
  295. }
  296.  
  297. /**
  298.  * @desc Top right explorer-specific controls
  299.  *
  300.  * @return string: HTML code
  301.  */
  302. function mefTopControls(){
  303.     $output='';
  304.     // Browse folders button
  305.     if(cfRGetVar('subFoldersIncluded')) $output.=mfButton(false,'javascript:setView(\'folders\')',outIcon('fi/med/folder'),'id="setViewFolders"',(cfRGetVar('view')=='folders')?'on':'');
  306.  
  307.     // Browse files button
  308.     $output.=mfButton(false,'javascript:setView(\'files\')',outIcon('fi/med/icoBlank'),'id="setViewFiles"',(cfRGetVar('view')=='files')?'on':'');
  309.  
  310.     // Tools button
  311.     if(mefHasTools()) {
  312.         if(is_array(cfRGetVar('fileTypeFilter')) && (in_array('audio',cfRGetVar('fileTypeFilter'))||in_array('video',cfRGetVar('fileTypeFilter'))))
  313.             $output.=mfButton(false,'javascript:setView(\'tools\')',outIcon('fi/med/icoM3U'),'id="setViewTools"',(cfRGetVar('view')=='tools')?'on':'');
  314.         else
  315.             $output.=mfButton(false,'javascript:setView(\'tools\')',outIcon('gearsM'),'id="setViewTools"',(cfRGetVar('view')=='tools')?'on':'');
  316.     }
  317.  
  318.     return $output;
  319. }
  320.  
  321. /**
  322.  * @desc Return true if resource has multiple downloads and/or upload
  323.  *
  324.  * @return boolean
  325.  */
  326. function mefHasTools(){
  327.     $filter=cfRGetVar('fileTypeFilter');
  328.     if(cfRGetVar('multipleDownloadAllowed') || (cfBGetVar('playlistFormat') && is_array($filter) && in_array('audio',$filter))) return true;
  329.     if(cfRGetVar('uploadAllowed')) return true;
  330.     return false;
  331. }
  332.  
  333.  
  334. /**
  335.  * @desc Return HTML code for multiple downloads list
  336.  *
  337.  * @return string
  338.  */
  339. function mefMultipleDownloadsInnerHTML(){
  340.     $output='';
  341.     if(cfRGetVar('playlist')) foreach (cfRGetVar('playlist') as $k=>$v) $output.='<div class="sli">'.cfUTF8Encode($v['label']).'</div>';
  342.     elseif(cfRGetVar('mDownloadList')) foreach (cfRGetVar('mDownloadList') as $k=>$v) $output.='<div class="sli"><img src="'.efIcon($k).'" class="frW ico16">'.cfUTF8Encode($k).'</div>';
  343.     return $output;
  344. }
  345.  
  346. /**
  347.  * @desc output script needed for sync/async update of tools view
  348.  * @param array $options: options:
  349.  *             'noMAddAll': no mAddAll button (used by mobile music DB scripts)
  350.  */
  351. function mefDisplayTools($options=false){
  352.     $output='';
  353.     $filter=cfRGetVar('fileTypeFilter');
  354.  
  355.     // Uploads
  356.     if(cfRGetVar('uploadAllowed')){
  357.         $output.='<div class="frame2">'.cfCaption('genFileUpload');
  358.         $output.='
  359. <form name="uploadForm" method="post" enctype="multipart/form-data" action="upload.php">
  360. <input type="hidden" name="UPLOAD_IDENTIFIER">
  361. <input type="hidden" name="ulDir" id="ulDir">
  362. <input type="hidden" name="postUlFile" id="postUlFile" value="">
  363. <input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">
  364. <input type="hidden" name="ulTransferId" id="ulTransferId" value="">
  365. <input type="file" id="ubId" name="ulInput" size="7">';
  366.         $output.=mfButton(false,'javascript:ul()',outIcon('ok'));
  367.         $output.='</div>';
  368.     }
  369.  
  370.     // Remote downloads
  371.     if(cfRGetVar('remoteDownloadAllowed')){
  372.         $output.='<div class="frame2">'.cfCaption('genDirectDownload');
  373.         $output.='<form name="ddBox" method="POST" onsubmit="return false">';
  374.         $output.='<input class="textInput" type="text" id="rdlInput" name="rdName" size="15" value="http://"> ';
  375.         $output.='<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
  376.         $output.=mfButton(false,'javascript:rdl();',outIcon('ok'),'id=rdlBt');
  377.         $output.='</form></div>';
  378.     }
  379.  
  380.     // Multiple downloads
  381.     if(cfRGetVar('multipleDownloadAllowed') || (cfBGetVar('playlistFormat') && is_array($filter) && in_array('audio',$filter))){
  382.         $output.='<div class="frame2"><div class="frame2Header">'.cfCaption('explorerMultipleDownload').'</div>';
  383.         // Multiple download & download buttons
  384.         $output.=mfButton(false,'javascript:mDownload()',outIcon('dl'))
  385.                 .((isset($options['noMAddAll']))?'':mfButton(false,'javascript:mAddAll()',outIcon('addMult')))
  386.                 .mfButton(false,'javascript:mSuppAll()',outIcon('eraser'));
  387.         // Playlist play all button
  388.         if(cfBGetVar('playlistFormat') && is_array($filter) && in_array('audio',$filter))
  389.             $output.=mfButton(false,'javascript:plPlayAll()',outIcon('play'));
  390.         // File's div
  391.         $output.='<div class="frame3" id="mdlF" style="height:80%;overflow:auto">';
  392.         $output.=mefMultipleDownloadsInnerHTML();
  393.         $output.='</div></div>';
  394.     }
  395.  
  396.     if(cfIsAsync()) {
  397.         echo cfAsyncXMLInnerHTMLbyId($output,'mainDiv');
  398.         die(cfAsyncFooter());
  399.     }
  400.     echo '<div id="mainDiv">'.$output.'</div></body></html>';
  401. }
  402.  
  403. /**
  404.  * @desc return JS array item corresponding to a file description
  405.  *
  406.  * @param array $value: properties of file
  407.  * @return string
  408.  */
  409. function mefFilePropertiesToJSArray($id,$value,$options=false){
  410.     // JS Array format :
  411.     //
  412.     // 00 - id,
  413.     // 01 - name,
  414.     // 02 - icon/thumbnail path
  415.     // 03 - downloadable (0 no, or 1 downloadable &  viewable or 2 viewable only)
  416.     // 04 - mdownloadable (0 or 1)
  417.     // 05 - size text,
  418.  
  419.     // Explorer
  420.     // 06 - unlinkable (0 or 1),
  421.     // 07 - renamable (0 or 1),
  422.     // 08 - excutable (0 or 1)
  423.  
  424.     // Images
  425.     // 06 - size
  426.  
  427.     // Audio
  428.     // 06 - title
  429.  
  430.     static $filter=null;
  431.     if($filter===null) $filter=cfRGetVar('fileTypeFilter');
  432.  
  433.     // ID, name
  434.     $output='Array('.$id.',"'.cfProtectFilename($value['name']).'",';
  435.  
  436.     // Icon / thumbnail
  437.     if(isset($options['tnw'])) {
  438.         // If a thumbnail exists, base smaller thumbnail on it
  439.         if(isset($value['thumbnail'])) $output.='"'.cfExtImage(isset($value['thumbnail'])?$value['thumbnail']:$value['completeFileName'],$options['tnw'],$options['tnh'],true,0,array('sq'=>1)).'",';
  440.  
  441.         else $output.='"'.cfExtImage($value['completeFileName'],$options['tnw'],$options['tnh'],true,0,array('sq'=>1)).'",';
  442.     }
  443.     elseif($filter==array('audio')) $output.='"",'; // Hard-coded icon in JS
  444.     else $output.='"'.$value['icon'].'",';
  445.  
  446.     // Download / view file
  447.     if($value['rights']['download'] && cfRGetVar('downloadShortcut')) $output.='1,';
  448.     elseif($value['rights']['download']) $output.='2,';
  449.     else $output.='0,';
  450.     // Multiple download
  451.     if($value['rights']['download'] && cfRGetVar('multipleDownloadAllowed')) $output.='1,'; else $output.='0,';
  452.     // Size
  453.     $output.="'".addslashes(str_replace(' ',' ',efFileSizeFormat($value['size'])))."',";
  454.  
  455.     if(!$filter || in_array('video',$filter)){
  456.         // Unlink
  457.         if($value['rights']['modify']) $output.='1,'; else $output.='0,';
  458.         // Rename
  459.         if($value['rights']['modify']) $output.='1,'; else $output.='0,';
  460.         // Execute
  461.         if($value['rights']['execute']) $output.='1'; else $output.='0';
  462.     }
  463.     elseif($filter==array('image')){
  464.         // Dimensions
  465.         $output.='"'.((isset($value['extra1']))?$value['extra1']:'').'"';
  466.     }
  467.     elseif($filter==array('audio')){
  468.         // Dimensions
  469.         $ai=efGetAudioInfo($value['completeFileName'],false);
  470.          $output.='"'.str_replace('"','"',cfUTF8Encode(((isset($ai['title']))?$ai['title']:$value['name']))).'"';
  471.     }
  472.     return $output.')';
  473. }
  474.  
  475. /**
  476.  * @Desc output script needed for sync/async update of folders view
  477.  *
  478.  */
  479. function mefDisplayFolders(){
  480.     /**
  481.      * Nb files in directory
  482.      */
  483.     $output='';
  484.     if(cfRGetVar('fileTypeFilter')==array('image'))    $icon='icoImage';
  485.     elseif(cfRGetVar('fileTypeFilter')==array('audio'))    $icon='icoMus';
  486.     elseif(cfRGetVar('fileTypeFilter')==array('video'))    $icon='icoVid';
  487.     elseif(cfRGetVar('fileTypeFilter')==array('image','audio','video'))    $icon='icoMultimedia';
  488.     else $icon='icoBlank';
  489.     if($_ENV['weezoResEfFiles']['nbFiles']==0) $icon='icoBlankNo';
  490.  
  491.     // Switch to files view if empty folder
  492.     if($_ENV['weezoResEfFiles']['nbSubDirs']==0 && $_ENV['weezoResEfFiles']['nbFiles']>0 && (!isset($_POST['data3']) || $_POST['data3']!='setView'))
  493.         return mefDisplayFiles();
  494.  
  495.     // Update script
  496.     $output='updtFolders("'.cfProtectFilename(cfResourceRelativePath(cfRGetVar('efCurrentDirectory'))).'","'.outIcon('fi/med/'.$icon).'","'.cfCaption('explorerFiles',$_ENV['weezoResEfFiles']['nbFiles']).'",Array(';
  497.  
  498.  
  499.     $i=0; $nb=0;
  500.  
  501.     /**
  502.      * Upper directory
  503.      */
  504.     if((cfFileRights(cfRGetVar('efCurrentDirectory')."/..",'state')=='authorized')){
  505.         $output.='".."';
  506.         $nb=1;
  507.     }
  508.  
  509.     /**
  510.      * Subdirectories
  511.      */
  512.     foreach ($_ENV['weezoResEfFiles'] as $file) if(is_array($file)){
  513.         if($file['type']=='file') continue;
  514.         if($i++<cfRGetVar('itemsPerPagePos')) continue;
  515.         if(cfRGetVar('itemsPerPage') && $nb>cfRGetVar('itemsPerPage')) break;
  516.  
  517.         if($nb>0) $output.=',';
  518.         if($file['type']=='dir'){
  519.             $output.='"'.cfUTF8Encode($file['completeFileName']).'"';
  520.         }
  521.         elseif($file['type']=='drive'){
  522.             $output.='Array("'.cfUTF8Encode($file['completeFileName']).'","'.$file['icon'].'")';
  523.         }
  524.         $nb++;
  525.     }
  526.  
  527.     $output.='),'.((cfRGetVar('itemsPerPagePos'))?1:0).','.((cfRGetVar('itemsPerPage') && $nb>cfRGetVar('itemsPerPage'))?1:0).')';
  528.  
  529.     if(isset($_POST['asyncRequest'])){
  530.         echo cfAsyncXMLJSaction($output);
  531.         echo cfAsyncFooter();
  532.         exit;
  533.     }
  534.     else
  535.         echo '<script type="text/javascript">'.$output.'</script></body></html>';
  536. }
  537.  
  538. /**
  539.  * @Desc output script needed for sync/async update of files view
  540.  *
  541.  */
  542. function mefDisplayFiles(){
  543.     $output ='updtFolders("'.cfProtectFilename(cfResourceRelativePath(cfRGetVar('efCurrentDirectory'))).'");';
  544.     $output.='updtFiles([';
  545.     $i=0;$nb=0;
  546.     $options=false;
  547.  
  548.      $filter=cfRGetVar('fileTypeFilter');
  549.  
  550.     // Compute images thumbnails dimensions
  551.     if(is_array($filter)&&in_array('image',$filter)){
  552.         $sw=max(cfGGetVar('userScreenWidth')-10,80);
  553.         $nbx=ceil($sw/100);    $w=floor($sw/$nbx);
  554.         if($w<70) {$nbx--;$w=floor($sw/$nbx);}
  555.         $options=array('tnw'=>$w,'tnh'=>$w);
  556.         // iPhone
  557.         if(cfBGetVar('name')=='iPhone'){$w=100;$nbx=3;}
  558.  
  559.         // Compute margin around images
  560.         $margin=max(1,($sw-($nbx*$w))/(2*$nbx));
  561.         $output='margin='.floor($margin).';'.$output;
  562.     }
  563.     // Audio files: include explorerFunctions for efGetAudioInfo
  564.     elseif(is_array($filter)&&in_array('audio',$filter)){require_once(INCLUDE_DIR.'explorerFunctions.php');}
  565.  
  566.     // Number of thumbnails per page (round to above value to fill table)
  567.     if(isset($nbx)) {
  568.         $nbPP=$nbx*ceil(cfRGetVar('itemsPerPagePos')/$nbx);
  569.         $iPP=$nbx*ceil(cfRGetVar('itemsPerPage')/$nbx);
  570.     }
  571.     else {
  572.         $nbPP=cfRGetVar('itemsPerPagePos');
  573.         $iPP=cfRGetVar('itemsPerPage');
  574.     }
  575.  
  576.     // Files information
  577.     foreach ($_ENV['weezoResEfFiles'] as $file) if(is_array($file) && $file['type']=='file'){
  578.         // Verify file is in displayed interval
  579.         if($i++<$nbPP) continue;
  580.         if(cfRGetVar('itemsPerPage') && $nb>=$iPP) break;
  581.  
  582.         if($nb>0) $output.=',';
  583.         $output.=mefFilePropertiesToJSArray($i-1,$file,$options);
  584.         $nb+=1;
  585.     }
  586.  
  587.     $output.='],'.((cfRGetVar('itemsPerPagePos'))?1:0).','.(($iPP && $nb>=$iPP)?1:0).')';
  588.  
  589.     // Set thumbnails width/height and nb thumbnails / rows
  590.     if(is_array($filter)&&in_array('image',$filter)) $output='imgw='.$w.';imgh='.$w.';imgx='.$nbx.';'.$output;
  591.  
  592.     if(isset($_POST['asyncRequest'])){
  593.         echo cfAsyncXMLJSaction($output);
  594.         echo cfAsyncFooter();
  595.         exit;
  596.     }
  597.     else
  598.         echo '<script type="text/javascript">'.$output.'</script></body></html>';
  599. }
  600. ?>